declare interface global {
  roads: Array<StructureRoad>
}

export = function (sourceId: string, targetIds?: string[]): ICreepConfig {
  return {
    source: (creep: Creep) => {
      let spawn: Structure = Game.getObjectById<Structure>(sourceId);
      if (creep.withdraw(spawn, RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) creep.moveTo(spawn)
    },
    // 建造
    target: (creep: Creep) => {
      for (let i = 0; i < targetIds.length; i++) {
        let targetObj: Structure = Game.getObjectById(targetIds[i]);
        if (targetObj && 'hitsMax' in targetObj && 'hits' in targetObj) {
          if (targetObj.hitsMax - targetObj.hits > 0) {
            if (creep.repair(targetObj) == ERR_NOT_IN_RANGE) creep.moveTo(targetObj);
            creep.moveTo(targetObj);
            return
          }
        }
      }
    },
    // 状态切换条件，稍后会给出具体实现
    switch: (creep: Creep) => creep.updateState()
  }
}